//
// Created by 紫霄 on 2020/5/10.
//

#ifndef LEETCODE_32_1_H
#define LEETCODE_32_1_H
#include <queue>
#include <vector>
using namespace std;

struct TreeNode {
  int val;
  TreeNode *left;
  TreeNode *right;
  TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
  vector<int> levelOrder(TreeNode *root) {
    queue<TreeNode *> nodes;
    vector<int> ans;
    if (!root)
      return ans;
    nodes.push(root);
    while (!nodes.empty()) {
      auto temp = nodes.front();
      ans.emplace_back(temp->val);
      if (temp->left)
        nodes.push(temp->left);
      if (temp->right)
        nodes.push(temp->right);
      nodes.pop();
    }
    return ans;
  }
};
#endif // LEETCODE_32_1_H
